class Brand < ActiveRecord::Base
  has_many :products,
    :conditions=>"DATE_ADD(`active_date`,INTERVAL `live_date` DAY) > now()",
    :order=>'sort_order desc'
  
  THUMB_IMAGE_SIZE = "80X40"
  GEOMETRY_IMAGE_SIZE = "160"

  file_column :image_url, :magick => {:geometry=>GEOMETRY_IMAGE_SIZE,
    :versions => { "thumb" => THUMB_IMAGE_SIZE}
  }

  def self.get_all_by_categery(category_id)
    self.find_by_sql(["SELECT DISTINCT b.*
FROM products p, categories c, brands b,categories c2
WHERE p.brand_id = b.id
AND ((p.category_id = c.id) or (p.category_id = c2.id and c2.parent_id = c.id))
AND (c.id = ? or c.parent_id = ?) order by sort_order desc",category_id,category_id])
  end
end
